//
//  NSObject+MZBlockKVO.h
//  MZToolkitDemo
//
//  Created by shenjialin on 2017/4/6.
//  Copyright © 2017年 shenjialin. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSObject (MZBlockKVO)

/* 无需在dealloc中removeObserve
 * 1、keyPaths储存被观察对象的属性路径
 * 2、identifier 标识观察者
 * 3、options观察的选项
 * 4、task观察到变化后触发的block
 */
- (void)mzAddObserverForKeyPath:(NSString *)keyPath identifier:(NSString *)identifier options:(NSKeyValueObservingOptions)options task:(void (^)(id obj, NSDictionary *change))task;
// 观察者观察被观察者的多久属性
- (void)mzAaddObserverForKeyPaths:(NSArray *)keyPaths identifier:(NSString *)identifier options:(NSKeyValueObservingOptions)options task:(void (^)(id obj, NSString *keyPath, NSDictionary *change))task;

/*移除identifier标示的观察者对keyPath的观察
 * 1、keyPaths储存被观察对象的属性路径
 * 2、identifier 标识观察者
 */
- (void)mzRemoveObserverForKeyPath:(NSString *)keyPath identifier:(NSString *)token;
// 移除identifier标示的观察者
- (void)mzRemoveObserversWithIdentifier:(NSString *)identifier;
// 移除所有的观察者
- (void)mzRemoveAllBlockObservers;

#pragma mark 存储数据

//归档数据并缓存，infor是遵从NSCoding的对象，key是唯一对应的关键字
- (BOOL)mzKeyedArchiverWithInfor:(id <NSCoding>)infor withKey:(NSString * __nullable)key;

//解归档数据，key是关键字
- (nullable id <NSCoding>)mzKeyedUnArchiverWithKey:(NSString * __nullable)key;

//解归档所有属性数据
- (void)mzReadAllAttrWithDecoder:(NSCoder * _Nonnull)aDecoder;
//归档所有属性数据
- (void)mzSaveAllAttrWithCoder:(NSCoder *_Nonnull)aCoder;

//根据关键字key删除缓存
- (BOOL)mzRemoveArchiveDataWithKey:(NSString * __nullable)key;
//删除所有缓存
- (BOOL)mzRemoveAllArchiveData;

@end
